﻿using System;
using System.IO;
using System.Windows.Forms;

namespace CefDemo
{
    class UIHelper
    {
        public static void OpenImageSelectDialog(Action<string> act)
        {
            var openFi = new OpenFileDialog();
            openFi.Filter = "图像文件(JPEG,GIF,BMP,etc.)|*.jpg;*.jpeg;*.gif;*.bmp;*.tif; *.tiff; *.png| JPEG 图像文件(*.jpg;*.jpeg)"
              + "|*.jpg;*.jpeg |GIF 图像文件(*.gif)|*.gif |BMP图像文件(*.bmp)|*.bmp|TIFF图像文件(*.tif;*.tiff)|*.tif;*.tiff|PNG图像文件(*.png)"
              + "| *.png |所有文件(*.*)|*.*";
            if (openFi.ShowDialog() == DialogResult.OK)
            {
                var path = Path.GetFullPath(openFi.FileName);
                act.Invoke(path);
            }
        }

        public static void OpenFileSelectDialog(Action<string> act)
        {
            var openFi = new OpenFileDialog();
            if (openFi.ShowDialog() == DialogResult.OK)
            {
                var path = Path.GetFullPath(openFi.FileName);
                act.Invoke(path);
            }
        }

        public static void OpenTxtSelectDialog(Action<string> act)
        {
            var openFi = new OpenFileDialog();
            openFi.Filter = "文本文件(*.txt) | *.txt";
            if (openFi.ShowDialog() == DialogResult.OK)
            {
                var path = Path.GetFullPath(openFi.FileName);
                act.Invoke(path);
            }
        }

        /// <summary>
        /// 设置提示
        /// </summary>
        /// <param name="control"></param>
        /// <param name="info"></param>
        public static void ShowTips(Control control, string info)
        {
            var tip = new ToolTip();
            // 设置显示样式
            tip.AutoPopDelay = 5000;//提示信息的可见时间
            tip.InitialDelay = 500;//事件触发多久后出现提示
            tip.ReshowDelay = 500;//指针从一个控件移向另一个控件时，经过多久才会显示下一个提示框
            tip.ShowAlways = true;//是否显示提示框
            tip.SetToolTip(control, info);
        }

        public static void ShowDeleteDialog(Action act, string msg = "确定要删除吗？")
        {
            var result = MessageBox.Show(msg, "温馨提示", MessageBoxButtons.OKCancel);
            if (result == DialogResult.OK) act?.Invoke();
        }

        public static void ShowOKDialog(Action act,string msg)
        {
            if (MessageBox.Show(msg, "温馨提示", MessageBoxButtons.OK) == DialogResult.OK)
            {
                act();
            }
        }
    }
}
